package com.example.controller;
import com.example.service.impl.OSSUploadServiceImpl;
import com.example.utils.ExceptionResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/oss")
public class OSSController {

    @Resource
    private OSSUploadServiceImpl ossUploadService;

    @PostMapping("/upload")
    public ExceptionResult uploadfile(@RequestParam("file") MultipartFile multipartFile){
        if (multipartFile.isEmpty()){
            return ExceptionResult.error(400,"文件错误!");
        }
        Long size = multipartFile.getSize();
        String originalFilename = multipartFile.getOriginalFilename();
        String contentType = multipartFile.getContentType();
        if (contentType.equals("png|jpg|gif|jpeg")){
            return ExceptionResult.error(400,"文件类型不正确!");
        }
        return ExceptionResult.success(ossUploadService.uploadfile(multipartFile));
    }

}
